using System;
using System.Collections.Generic;
using System.Text;

namespace Wrath.Xml.Objects
{
    public class ControlFrame : IElementContainer
    {
        private string name;
        public string Name
        {
            get { return name; }
            set { name = value; }
        }

        private string offset;

        public string Offset
        {
            get { return offset; }
            set { offset = value; }
        }

        public ControlFrame(Element element)
        {
            Element subElement = element.FindFirstElement("name", false);
            if (subElement != null)
            {
                name = subElement.Value.Substring(0);
            }

            subElement = element.FindFirstElement("offset", false);
            if (subElement != null)
            {
                offset = subElement.Value.Substring(0);
            }
        }	
	
        #region IElementContainer Members

        private Element sourceElement;
        public Element SourceElement
        {
            get { return sourceElement; }
        }

        public void Commit()
        {
            sourceElement = new Element("frame");

            if (!String.IsNullOrEmpty(name))
            {
                Element element = new Element("name");
                element.Value = name;
                sourceElement.ChildElements.Add(element);
            }

            if (!String.IsNullOrEmpty(offset))
            {
                Element element = new Element("offset");
                element.Value = offset;
                sourceElement.ChildElements.Add(element);
            }

        }

        #endregion
    }
}
